package com.jingsheng.adapter;

import java.util.List;

import com.jingsheng.bean.ImagesBean;
import com.jingsheng.corp.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;

public class ProdGallaryAdapter extends BaseAdapter {

	private List<ImagesBean> list;
    LayoutInflater inflater;
    public ProdGallaryAdapter(Context context,List<ImagesBean> list) {
        this.list=list;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CacheView cacheView;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.products_gallery, null);
            cacheView=new CacheView();
            cacheView.prod_name = (TextView) convertView.findViewById(R.id.pro_name);
            cacheView.prod_size=(TextView) convertView.findViewById(R.id.pro_size);
            cacheView.prod_spec=(TextView) convertView.findViewById(R.id.pro_spec);
            cacheView.imgv_img=(ImageView) convertView.findViewById(R.id.pro_img);
            convertView.setTag(cacheView);
        }else{
            cacheView=(CacheView) convertView.getTag();
        }
        cacheView.prod_size.setText(list.get(position).getProdDescSize());
        cacheView.prod_spec.setText(list.get(position).getProdDescSpec());
        cacheView.imgv_img.setImageResource(list.get(position).getImgUrl());
        cacheView.prod_name.setText(list.get(position).getProdName());
        convertView.setLayoutParams(new Gallery.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        //cacheView.imgv_img.setImageURI(list.get(position).getImgUrl());
        return convertView;
    }
    
    private static class CacheView {
    	TextView prod_name;
        TextView prod_size;
        TextView prod_spec;
        ImageView imgv_img;
    }
}
